﻿using System;
using System.Globalization;
using System.Threading;
using System.Windows.Data;

namespace estoque
{
    public class DateTimeConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            DateTime date = (DateTime)value;
            string content = date.ToString("HH:mm", Thread.CurrentThread.CurrentCulture);

            return content;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string strValue = value.ToString();
            DateTime resultDateTime;

            if (DateTime.TryParse(strValue, Thread.CurrentThread.CurrentCulture, DateTimeStyles.None, out resultDateTime))
            {
                return resultDateTime;
            }

            return value;
        }
    }
}